package com.cuitrip.component;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.cuitrip.service.R;
import com.pnikosis.materialishprogress.ProgressWheel;

/**
 * Created by MiJack on 2015/12/23.
 */
public class LoadingButton extends FrameLayout {

    TextView button;
    ProgressWheel wheel;

    public LoadingButton(Context context) {
        this(context, null);
    }

    public LoadingButton(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public LoadingButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.base_loading_button, this, false);
        addView(view);
        button = (TextView) view.findViewById(R.id.button);
        wheel = (ProgressWheel) view.findViewById(R.id.wheel);
        hideLoading();
    }

    public TextView getButton() {
        return button;
    }

    public ProgressWheel getWheel() {
        return wheel;
    }

    public void setText(int res) {
        button.setText(res);
        hideLoading();
    }

    public void showLoading() {
        button.setVisibility(INVISIBLE);
        wheel.setVisibility(VISIBLE);
    }

    public void hideLoading() {
        button.setVisibility(VISIBLE);
        wheel.setVisibility(INVISIBLE);
    }

    public boolean isLoading() {
        return button.getVisibility()==INVISIBLE;
    }
}
